| Total Complexity | 1 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
| 9 | |||
| 10 | @CommandHandler(CreateEventCommand) |
||
| 11 | export class CreateEventCommandHandler extends AbstractEventCommandHandler { |
||
| 12 | constructor( |
||
| 13 | @Inject('ISchoolRepository') schoolRepository: ISchoolRepository, |
||
| 14 | @Inject('IUserRepository') userRepository: IUserRepository, |
||
| 15 | @Inject('IEventRepository') |
||
| 16 | private readonly eventRepository: IEventRepository, |
||
| 17 | ) { |
||
| 18 | super(schoolRepository, userRepository); |
||
| 19 | } |
||
| 20 | |||
| 21 | public async execute(command: CreateEventCommand): Promise<string> { |
||
| 22 | const { date, summary, userId, schoolId } = command; |
||
| 23 | |||
| 24 | const [ user, school ] = await Promise.all([ |
||
| 25 | this.getUser(userId), |
||
| 26 | this.getSchool(schoolId) |
||
| 27 | ]); |
||
| 28 | |||
| 29 | const event = await this.eventRepository.save( |
||
| 30 | new Event( |
||
| 31 | date, |
||
| 32 | user, |
||
| 33 | school, |
||
| 34 | summary |
||
| 35 | ) |
||
| 36 | ); |
||
| 37 | |||
| 38 | return event.getId(); |
||
| 39 | } |
||
| 41 |